package org.budo.dubbo.protocol.http.invocation.adapter;

import lombok.ToString;

/**
 * @author lmw
 */
@ToString
public class ProtocolRequestHolder {
    private static final ThreadLocal<ProtocolRequest> _PROTOCOL_REQUEST = new InheritableThreadLocal<ProtocolRequest>();

    public ProtocolRequestHolder(ProtocolRequest protocolRequest, ProtocolResponse protocolResponse) {
        _PROTOCOL_REQUEST.set(protocolRequest);
    }

    public static String getHeader(String key) {
        ProtocolRequest protocolRequest = _PROTOCOL_REQUEST.get();
        return null == protocolRequest ? null : protocolRequest.getHeader(key);
    }

    public static void setThreadLocal(ProtocolRequest protocolRequest, ProtocolResponse protocolResponse) {
        _PROTOCOL_REQUEST.set(protocolRequest);
    }

    public static void removeThreadLocal() {
        _PROTOCOL_REQUEST.remove();
    }
}